﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>EnvSet - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The EnvSet function writes a value to a variable contained in the environment." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>EnvSet</h1>

<p>将值写入环境变量包含的<a href="../Concepts.htm#environment-variables">变量</a>中.</p>

<pre class="Syntax"><span class="func">EnvSet</span> EnvVar, Value</pre>
<h2 id="Parameters">参数</h2>
<dl>

  <dt>EnvVar</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>要使用的<a href="../Concepts.htm#environment-variables">环境变量</a>的名称, 例如 &quot;COMSPEC&quot; 或 &quot;PATH&quot;.</p>
  </dd>

  <dt>Value</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>要设置到<a href="../Concepts.htm#environment-variables">环境变量</a>的值.</p>
  </dd>

</dl>

<h2 id="Error_Handling">错误处理</h2>
<p>失败时抛出异常.</p>

<h2 id="Remarks">备注</h2>
<p>操作系统限制每个环境变量的文本最多为 32 KB.</p>
<p>此函数创建或改变的环境变量只有由此脚本通过 <a href="Run.htm">Run</a> 或 <a href="Run.htm">RunWait</a> 运行的程序才可以访问. 有关详细信息, 请参阅<a href="../Concepts.htm#environment-variables">环境变量</a>.</p>
<p>此函数的存在是因为<a href="../Variables.htm">普通脚本变量</a>没有存储在环境变量中. 这是因为性能会变差, 也因为操作系统将环境变量限制为 32 KB.</p>
<h2 id="Related">相关</h2>
<p><a href="EnvGet.htm">EnvGet</a>, <a href="../Concepts.htm#environment-variables">环境变量</a>, <a href="Run.htm">Run</a>, <a href="Run.htm">RunWait</a></p>
<h2 id="Examples">示例</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>EnvSet "AutGUI", "Some text to put in the variable."</pre>
</div>

</body>
</html>